package com.gitee.wsl.lifecycle.nav

import com.gitee.wsl.data.state.statekeeper.SerializableContainer
import com.gitee.wsl.data.value.MutableValue
import com.gitee.wsl.data.value.Value

//class NavigatorController<V>(
//    val source: NavigationSource<Navigation.Event<V>>,
//    initItems:V
//):Navigator<V> {
//    private val nav = Relay<NavEvent<V>>()
//    private val navState = MutableValue(initItems)
//    val state: Value<V> = navState
//
//    init {
//        nav.subscribe(::onEvent)
//        val cancellation = source.subscribe { nav.accept(NavEvent.Event(it)) }
//
//        nav.accept(
//            NavEvent.Init(
//                initialState = restoredNavState ?: initialState(),
//                savedChildState = restoredState?.childState?.takeUnless { restoredNavState == null },
//            ),
//        )
//
//    }
//
//    override fun navigate(transformer: (V) -> V, onComplete: (newPages: V, oldPages: V) -> Unit) {
//        nav.accept(NavEvent.Event(Navigation.Event(transformer, onComplete)))
//    }
//
//    private fun onEvent(event: Navigation.Event<V>) {
//        val oldNavState = navState.value
//        val newNavState = event.transformer(oldNavState)
//        setState(navState = newNavState)
//        event.onComplete(newNavState, oldNavState)
//    }
//
//    private fun setState(navState: V) {
//        this.navState.value = navState
//    }
//
//    private sealed interface NavEvent<V> {
//        class Init<V>(
//            val initialState: V,
//            val savedChildState: Map<Int, SerializableContainer>?,
//        ) : NavEvent<V>
//
//        class Event<V>(val event: Navigation.Event<V>) : NavEvent<V>
//    }
//}